﻿using System;
using System.Data;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MxWeiXinPF.Common;
using MxWeiXinPF.BLL;

namespace MxWeiXinPF.Web.admin.wxapp
{
    public partial class paramAppEdit : Web.UI.ManagePage
    {

        private string action = MXEnums.ActionEnum.Add.ToString(); //操作类型

        wxapp_appinfo dzpBll = new wxapp_appinfo();
      

        protected void Page_Load(object sender, EventArgs e)
        {
            string _action = MXRequest.GetQueryString("action");
            int id = 0;
            if (!string.IsNullOrEmpty(_action) && _action == MXEnums.ActionEnum.Edit.ToString())
            {

                this.action = MXEnums.ActionEnum.Edit.ToString();//修改类型
                if (!int.TryParse(Request.QueryString["id"] as string, out  id))
                {
                    JscriptMsg("传输参数不正确！", "back");
                    return;
                }
                if (!dzpBll.Exists(id))
                {
                    JscriptMsg("记录不存在或已被删除！", "back");
                    return;
                }
            }
            if (!Page.IsPostBack)
            {

                if (action == MXEnums.ActionEnum.Edit.ToString()) //修改
                {
                    ShowInfo(id);
                }
                
            }
        }



        #region 赋值操作=================================
        //1e2124dd04e11d01b9df2865f85944be
        private void ShowInfo(int id)
        {
            hidid.Value = id.ToString();
            Model.wxapp_appinfo model = dzpBll.GetModel(id);

            txtwxappName.Text = model.wxappName;
            txtpageUrl.Text = model.pageUrl;
            txtappName.Text = model.appName;
            //txtappId.Text = model.appId;
            //txtappSecret.Text = model.appSecret;
            //txtwxappShopId.Text = model.wxappShopId;
        }

        #endregion



        //保存
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            
            int id = MyCommFun.Str2Int(hidid.Value);
            #region  //先判断
            string strErr = "";
            if (this.txtwxappName.Text.Trim().Length == 0)
            {
                strErr += "小程序名称不能为空！";
            }
            if (this.txtpageUrl.Text.Trim().Length == 0)
            {
                strErr += "路径不能为空！";
            }

            if (this.txtappName.Text.Trim().Length == 0)
            {
                strErr += "应用名称不能为空！";
            }


            //if (this.txtappId.Text.Trim().Length == 0)
            //{
            //    strErr += "appId不能为空！";
            //}

            //if (this.txtappSecret.Text.Trim().Length == 0)
            //{
            //    strErr += "appSecret不能为空！";
            //}

             

            if (strErr != "")
            {
                JscriptMsg(strErr, "back");
                return;
            }
           
            #endregion

            #region 赋值
            Model.wxapp_appinfo model = new Model.wxapp_appinfo();
           
            if (id > 0)
            {
                model = dzpBll.GetModel(id);
            }

            model.wxappName = txtwxappName.Text.Trim();

            model.pageUrl = txtpageUrl.Text.Trim();

            model.appName = txtappName.Text.Trim();
            //model.appId = txtappId.Text.Trim();
            //model.appSecret = txtappSecret.Text.Trim();
           // model.wxappShopId = txtwxappShopId.Text.Trim();
           

            #endregion

            if (id <= 0)
            {  //新增
              
                model.createTime = DateTime.Now;
                model.status = 0;
                model.createPerson = GetAdminInfo().user_name;
                //1新增主表
                id = dzpBll.Add(model);

               
                AddAdminLog(MXEnums.ActionEnum.Add.ToString(), "添加小程序（参数设置），主键为" + id); //记录日志//1e2124dd04e11d01b9df2865f85944be
                JscriptMsg("添加小程序（参数设置）成功！", "paramAppList.aspx");
            }
            else
            {   //修改

                model.updateTime = DateTime.Now;
                dzpBll.Update(model);

                AddAdminLog(MXEnums.ActionEnum.Edit.ToString(), "修改小程序（参数设置），主键为" + id); //记录日志
                JscriptMsg("修改小程序（参数设置）成功！", "paramAppList.aspx");
            }

        }

      

 

    }
}